//简单工厂模式
#include<iostream>
#include<memory>
using namespace std;

class Fruit{
    public:
    virtual void show(){
        cout<<"这是一个水果"<<endl;
    }
};
class Apple:public Fruit{
    public:
    void show() override{
        cout<<"这是一个苹果"<<endl;
    }
};
class Banana:public Fruit{
    public:
    void show() override{
        cout<<"这是一个香蕉"<<endl;
    }
};
class Orange:public Fruit{
    public:
    void show() override{
        cout<<"这是一个橘子"<<endl;
    }
};
class FruitFactor{
    public:
    static shared_ptr<Fruit> create(const string& name){
        if(name=="苹果"){
            return make_shared<Apple>();
        }else if(name=="香蕉"){
            return make_shared<Banana>();
        }else{
            return make_shared<Orange>();
        }
    }
};


int main()
{
    shared_ptr<Fruit> fruit=FruitFactor::create("苹果");
    fruit->show();
    fruit=FruitFactor::create("香蕉");
    fruit->show();
    
    return 0;
}